package com.lulu.baselib

import android.graphics.Bitmap
import android.util.Log
import com.lulu.baselib.util.ImageUtil
import org.junit.Assert
import org.junit.Test

import org.junit.Assert.*
import java.io.ByteArrayOutputStream
import java.util.concurrent.CountDownLatch

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    var imgUrl =
        "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600707901148&di=5198c1e67be855628977619008bad75f&imgtype=0&src=http%3A%2F%2Fa2.att.hudong.com%2F86%2F10%2F01300000184180121920108394217.jpg";

    fun log(msg:String){
//        Log.d("ShareTest", msg)
    }

    @Test
    fun loadImg() {
        log("start123123")
        val countDown = CountDownLatch(1)
        var bm: Bitmap? = null
        ImageUtil.loadImage(imgUrl, object : ImageUtil.LoadImageCallback {
            override fun onLoadSuccess(bitmap: Bitmap?) {
                val byteCount = bitmap?.byteCount
                log("byteCount = $byteCount")

                var out = ByteArrayOutputStream()
                bitmap?.compress(Bitmap.CompressFormat.JPEG, 100, out)
                log("bytes byteCount = ${out.size()}")

                bm = bitmap!!;
                countDown.countDown()
            }

            override fun onLoadFailed(msg: String?) {
                log("request failed:$msg")
            }

        })
        countDown.await()
        log("finish")

        Assert.assertNull(bm)   //failed
    }
}
